<?php

/**
 * This is the model class for table "{{post}}".
 *
 * The followings are the available model relations:
 * @property Category $category
 */
class MassUpdateForm extends CFormModel
{
	public $category_id;
	public $status;
	public $rating;
	public $visibility;
	public $post_ids;
	
	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('rating, status, category_id, visibility, post_ids', 'safe'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels() {
		return array(
			'category_id' => 'Category',
		);
	}

	public function getStatusListData() {
		return Post::model()->getStatusListData();
	}
	
	public function getRatingListData() {
		return Post::model()->getRatingListData();
	}
	
	public function getVisibilityListData() {
		return Post::model()->getVisibilityListData();
	}

	public function getCategoryListData() {
		return Post::model()->getCategoryListData();
	}
	
	public function save() {
		$postIds = str_replace('_', ',', $this->post_ids);
		$attrs = array_filter($this->attributes);
		unset($attrs['post_ids']);
		return Post::model()->updateAll($attrs, "id IN ($postIds)");
	}
}